//
//  InviteActView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/10/21.
//

import SwiftUI

//邀请活动
struct InviteActItemView: View {
    var bean: InviteRewardBean
    @ObservedObject var viewModel : InviteActViewModel

    var body: some View {
        HStack(alignment:.center) {
            AvatarImageView(url: bean.avatar ?? "", size: 50)
                .blur(radius: 5)
                .clipShape(Circle())
                .contentShape(Rectangle())
                .onTapGesture {
                    pathManager.jump(type: JumpType.AI_ROLE, data: bean)
                }
            VStack(alignment:.leading, spacing: 2){
                HStack(spacing: 5) {
                    Text(bean.showName()).font(.system(size: 14, weight: .medium)).foregroundColor(.bgNormalText)
                    if (bean.reward ?? false) == false { //显示未领取标签
                        Text("未领取").font(.system(size: 8)).foregroundColor(Color.white).lineLimit(2)
                            .padding(.horizontal, 2)
                            .padding(.vertical, 2)
                            .background(themeManager.themeColor)
                            .clipShape(RoundedRectangle(cornerRadius: 3))
                    }
                    Spacer()
                }
                Text(bean.content ?? "")
                    .font(.system(size: 12))
                    .foregroundColor(.bgNormalText4).lineLimit(1)
                    .multilineTextAlignment(.leading)  // 明确设置多行文本对齐方式
            }
            Spacer()
            ZStack {
                Text("+\(bean.getCountStr())")
                    .font(.system(size: 14))
                    .foregroundColor(.white)
                    .padding(.horizontal, 15)
                    .padding(.vertical, 7)
                    .background(bean.reward == true ? Color.disabled :themeManager.themeColor)
                    .cornerRadius(20)
                    .contentShape(Rectangle())
                    .onTapGesture {
                        if bean.reward == true {
                            return
                        }
                        if bean.test == true {
                            showTipsDialog(text: "当前展示的是‘示例奖励’不支持领取。请完成邀请任务，即可领取奖励")
                            return
                        }
                        viewModel.doReceive(bean: bean)
                    }
            }.frame(maxHeight: .infinity, alignment: .center)
        }.frame(maxWidth: .infinity,alignment:.leading)
            .padding(.horizontal,15)
            .padding(.vertical, 10)
            .background(.bgItem)
            .cornerRadius(15)
    }
}

#Preview {
    InviteActItemView(bean: InviteRewardBean(), viewModel: InviteActViewModel())
}
